package com.future.baselib.utils;

import android.content.Context;
import android.media.Image;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.future.baselib.R;

import javax.microedition.khronos.opengles.GL;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

/**
 * 默认glide加载方法
 * Created by jniu on 2018/1/11 0011.
 */

public class GlideUtils {

    public static void loadImage(Context context, String url, ImageView imageView) {
        loadImage(context, url, getDefaultOptions(), imageView);
    }

    public static void loadTopRoundImage(Context context, String url, ImageView imageView) {
        Glide.with(context).load(url).apply(RequestOptions
                .bitmapTransform(new RoundedCornersTransformation(20, 0, RoundedCornersTransformation.CornerType.TOP))
                .dontAnimate()
                .placeholder(R.color.black4)
                .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC))
                .into(imageView);
    }

    public static void loadImage(Context context, String url, RequestOptions options, ImageView imageView) {
        Glide.with(context).applyDefaultRequestOptions(options).load(url).into(imageView);
    }

    private static RequestOptions getDefaultOptions() {
        return new RequestOptions()
                .dontAnimate()//不执行动画
                .placeholder(R.color.black4)//占位图
                .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)//缓存机制
                ;
    }
}
